package com.review.study;


import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerSocketOperat2 {
    public static void main(String[] args) {
        ServerSocket serverSocket;

        try {
            serverSocket = new ServerSocket(8099);
            while (true) {
                System.out.println("等待客户端连接");
                Thread.sleep(1000);
                Socket socket = serverSocket.accept();
                System.out.println(socket.getPort() + "" + socket.getInetAddress());
                InputStream inputStream = socket.getInputStream();
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

                    System.out.println("客户端说：" + bufferedReader.readLine());
                    socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
